<?php
/**
 *
 * @author jigal
 *
 */
class EventManager_Resource_User extends SF_Model_Resource_Db_Table_Abstract implements EventManager_Resource_User_Interface{

	/**
	 *
	 * @var unknown_type
	 */
	protected $_name = 'user';
	/**
	 *
	 * @var unknown_type
	 */
	protected $_primary = 'usr_id';
	/**
	 *
	 * @var unknown_type
	 */
	protected $_rowClass = 'EventManager_Resource_User_Item';
	/**
	 * (non-PHPdoc)
	 * @see modules/eventManager/models/resources/User/EventManager_Resource_User_Interface#getUserById($id)
	 */
	public function getUserById($id){
		return $this->find($id)->current();
	}
	/**
	 * (non-PHPdoc)
	 * @see modules/eventManager/models/resources/User/EventManager_Resource_User_Interface#getUserByEmail($email)
	 */
	public function getUserByEmail($email,$ignoreUser = null){

		$select = $this->select();
		$select->where('usr_email = ?', $email);
		if(null != $ignoreUser){
			$select->where('usr_email != ?', $ignoreUser->usr_email);
				
		}
		return $this->fetchRow($select);
	}
	/**
	 * (non-PHPdoc)
	 * @see modules/eventManager/models/resources/User/EventManager_Resource_User_Interface#getUsers($paged, $order)
	 */
	public function getUsers($paged = false, $order = null){
		if(true === is_array($order)){
			$select->order($order);
		}
		if(null !== $paged){
			$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
			$count = clone $select;
			$count->reset(Zend_Db_Select::COLUMNS);
			$count->reset(Zend_Db_Select::FROM);
			$count->from('user', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`'));
			$adapter->setRowCount($count);
			$paginator = new Zend_Paginator($adapter);
			$paginator->setItemCountPerPage(15)
			->setCurrentPageNumber((int) $paged);
		}
		return $this>fetchAll($select);
	}

}